/*
 * function TreeNode(x) {
 *   this.val = x;
 *   this.left = null;
 *   this.right = null;
 * }
 */

/**
 * 
 * @param root TreeNode类 
 * @param o1 int整型 
 * @param o2 int整型 
 * @return int整型
 */
 function lowestCommonAncestor( root ,  o1 ,  o2 ) {
  // write code here
  return findRoot(root ,  o1 ,  o2).val
}
function findRoot(root,o1,o2){
  if(root === null) return null
  if(root.val === o1 || root.val === o2) return root
  let left = findRoot(root.left,o1,o2)
  let right = findRoot(root.right,o1,o2)
  if(left && right){
    return root
  }
  if(left) return left
  if(right) return right
}
module.exports = {
  lowestCommonAncestor : lowestCommonAncestor
};